//
//  KyVisitorView.swift
//  KySwiftPro
//
//  Created by fangyukui on 2017/10/20.
//  Copyright © 2017年 fangyukui. All rights reserved.
//

import UIKit

class KyVisitorView: UIView {
    
    var visitorInfo:Dictionary<String, Any>?{
        didSet{
            guard let icon =  visitorInfo?["iconName"] as? String,
                  let title = visitorInfo?["title"] as? String  else {
                return
            }
            titleTip.text = title
            if icon == "" {
                iconView.image = UIImage(named: "visitordiscover_feed_image_smallicon")
                hourseIconView.image = UIImage(named: "visitordiscover_feed_image_house")
                
            }
            hourseIconView.image = UIImage(named: icon)
            
            
        }
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: 私有控件
    lazy var iconView = UIImageView()
    
    lazy var hourseIconView = UIImageView()
    
    lazy var titleTip :UILabel = UILabel(title: "关注一下人关注一下人关注一下人", fontSize: 12)
    
    lazy var registerBtn : UIButton  =  {
        let btn = UIButton()
        btn.setTitle("注册", for: .normal)
        btn.backgroundColor = .orange
        btn.sizeToFit()
        return btn
    }()
    
    lazy var loginBtn :  UIButton  =  {
        let btn = UIButton()
        btn.setTitle("登陆", for: .normal)
        btn.backgroundColor = .orange
        btn.sizeToFit()
        return btn
    }()

}

extension KyVisitorView{
     fileprivate func setupUI(){
        backgroundColor = .white
        addSubview(iconView)
        addSubview(hourseIconView)
        addSubview(titleTip)
        addSubview(registerBtn)
        addSubview(loginBtn)
        for v in self.subviews {
            v.translatesAutoresizingMaskIntoConstraints = false
        }
        addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: iconView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: hourseIconView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: hourseIconView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: titleTip, attribute: .centerX, relatedBy: .equal, toItem: iconView, attribute: .centerX, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: titleTip, attribute: .top, relatedBy: .equal, toItem: hourseIconView, attribute: .bottom, multiplier: 1, constant: 15))
       
        addConstraint(NSLayoutConstraint(item: registerBtn, attribute: .left, relatedBy: .equal, toItem: iconView, attribute: .left, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: registerBtn, attribute: .top, relatedBy: .equal, toItem: iconView, attribute: .bottom, multiplier: 1, constant: 80))
        addConstraint(NSLayoutConstraint(item: loginBtn, attribute: .right, relatedBy: .equal, toItem: iconView, attribute: .right, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: loginBtn, attribute: .top, relatedBy: .equal, toItem: iconView, attribute: .bottom, multiplier: 1, constant: 80))

    }
}


